
use "D:\百度云同步盘\清华\科研\数据\私营企业数据2010-2012\2012.dta",clear



collapse (mean) party_ind=b18a4, by(b15a) 


sort b15a

save "D:\百度云同步盘\清华\科研\论文\He & Liu\制度涉入和家族企业应对\数据\party_ind_temp2012.dta",replace

merge 1:m  b15a using "D:\百度云同步盘\清华\科研\数据\私营企业数据2010-2012\2012.dta"

replace party_ind=. if b15a==.

g year = 2012

********************************************************************************
********************************* 控制变量 *********************************
********************************************************************************

*****************************
*** Firm Level ***
*****************************

*企业历史
tab b11
g firm_year = 2012-b11

*雇员人数
sum b16b1a // 全部雇员
g employee = b16b1a
replace employee = . if employee < 0 
g log_employee = log(employee+1)

***企业资本构成(最近1年)

*总额(万元)
sum b14a6b
g interest_total = b14a6b
replace interest_total =. if interest_total <0

*您自己和家人(衡量家族涉入) %
g interest_of = b14a1b
replace interest_of =. if interest_of <0
replace interest_of =. if interest_of > 100

***企业重大决策权
tab b19a 
	// 1=您本人 2=股东大会 3=董事会 4=高管会议 5=其他
g decion_big = b19a
g decion_big_dummy = decion_big
recode decion_big_dummy 1=1 2/5= 0 // 0=非本人 1=本人 
tab decion_big_dummy

***企业日常管理
tab b19b1
	// 1=您本人 2=职业经理人 3=高层管理会议 4=其他
g decion_manage = b19b1
g decion_manage_dummy = decion_manage
recode decion_manage_dummy 1=1 2/4= 0 // 0=非本人 1=本人 
tab decion_manage_dummy

*********************
*Industry Level
*********************

*行业类型 (实体vs非实体-房地产和金融保险)-参考范晓光和吕鹏(2018)
tab b15a // 1-19
tab b15a, nol // 1-19
tab b15b
tab b15c
g indus_1 = b15a
g indus_2 = b15b
g indus_3 = b15c

/*
recode indus_1 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
recode indus_2 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
recode indus_3 10/11=0 1/9=1 12/19=1  // 0=非实体 1=实体
g indus_real = indus_1
tab indus_real
*/

g industry_man = .
replace industry_man = 0 if indus_1 != 3 & indus_2 != 3 & indus_3 != 3  // 非制造业
replace industry_man = 1 if indus_1 == 3 | indus_2 == 3 | indus_3 == 3  // 制造业
tab industry_man



********************************************************************************
***********************************Individual Level****************************
********************************************************************************

*性别
tab a1
tab a1, nol // 男=1 女=2
g gender = a1
recode gender 1=1 2=0  // 女=0 男=1

*年龄/出生年份
tab a2
g age = 2012-a2

*学历 (0=初中及以下 1=高中 2=大专及以上)-参考范晓光和吕鹏(2018)
tab a3
tab a3, nol 
   // 1=小学及以下  2=初中 3=高中、中专  4=大专 5=大学 6-研究生
g edu_cate = a3
recode edu_cate 1/2=0 3=1 4/6=2  
tab edu_cate

*学历 (0=高中及以下 1=大专及以下)
tab a3
tab a3, nol 
g edu_dummy = a3
recode edu_dummy 1/3=0 4/6=1
tab edu_dummy   

*政治面貌
tab a5a1 // 1=党员 2=民主党派  3-未参加
g party_mem = .
replace party_mem = 1 if a5a1 == 1
replace party_mem = 0 if a5a1 == 2 | a5a1 == 3 | a5a1==.
tab party_mem

*两委委员
tab a8a
tab a8a, nol // 1-3 , 3=都不是
g twocm = a8a
recode twocm 1/2 =1 3=0 
tab twocm // 1=是 0=不是

*工商联
tab c28a1 // 1=是 2=否
tab c28a1, nol
g gongshanglian = c28a1
recode gongshanglian 1=1 2=0 // 1=是 0=否
tab gongshanglian

*地位感知(经济/社会/政治) 数值越小，地位越高
tab a10a // 收入水平 1-10
tab a10b // 社会地位
tab a10c // 政治参与
g status_e = a10a
g status_s = a10b
g status_p = a10c
replace status_e =. if status_e <0
replace status_s =. if status_s <0
replace status_p =. if status_p <0
g status_tl = (status_e+status_s+status_p)/3

********************************************************************************
********************************* 党建 *********************************
********************************************************************************

*设立党组织(在您的企业中，有无下列组织?) 
sum b18a1 // 股东会
sum b18a2 // 董事会
sum b18a3 // 监事会
sum b18a4 // 党支部  0=无 1=有
sum b18a5 // 工会
sum b18a6 // 职工代表大会
g structure_share = b18a1
g structure_chair = b18a2
g structure_audit = b18a3
g structure_party = b18a4
g structure_union = b18a5
g structure_assemble = b18a6
tab structure_party



*如果您是中共党员，您在企业是否担任党的职务？
tab a6a // ⑴担任企业的党委（总支、支部）书记、副书记 ⑵委员 ⑶未担任
tab a6a, nol
g firm_shuji = a6a
recode firm_shuji 1=1 2/3=0 .=0 // 0=否 1=是

tab firm_shuji

*如果您是中共党员，您在地方或基层党委是否担任党的职务？
tab a6b1 // ⑴担任地方或基层党委（总支、支部）书记、副书记 ⑵委员 ⑶未担任
tab a6b1, nol 
g local_shuji = a6a
recode local_shuji 1=1 2/3=0 // 0=否 1=是

*如果您在地方或基层党委是否担任党的职务，是哪一级?
tab a6b2 // ⑴城镇居委会 ⑵乡镇（街道）级 ⑶县级 ⑷地级 ⑸省级

*A.您认为私营企业是否应该设立党组织？
tab c31a // ⑴应该 ⑵不应该
g pa_should = c31a
recode pa_should 2=0 1=1 // 1=应该 0=不应该
tab pa_should 

*B.您认为如果在私营企业里建立党组织，它应该发挥什么作用？
sum c31b1 c31b2 c31b3 c31b4 c31b5 c31b6
 // ⑴保证政治方向 ⑵促进企业发展 ⑶引领企业文化 ⑷凝聚职工群众 ⑸维护企业和谐稳定 ⑹其他（请写明）
 
*C.您认为私营企业党组织应由哪一种上级党组织管理更适合？ 
tab c31c // (1)属地党委 (2)工商管理部门党组（党委、党工委） (3)工商联党组 ⑷其他（如党的社会工委）（请写明）


********************************************************************************
********************************* 经营 *********************************
********************************************************************************

*企业资产 - 所有者权益总额(万元)
*sum b14a6b
*g interest_total = b14a6b
*replace interest_total =. if interest_total <0

******
*绩效*
******

*销售收入
g revenue_latest = b16d1
replace revenue_latest =. if revenue_latest < 0
g log_revenue_latest = log(revenue_latest+1)

winsor2 revenue_latest, cuts(1 99) suffix(_w) label // 缩尾
sum revenue_latest_w 
g log_revenue_latest_w = log(revenue_latest_w+1)

*利润
sum b16f1
g profit_latest = b16f1
replace profit_latest =. if profit_latest < 0
g log_profit_latest = log(profit_latest+1)

winsor2 profit_latest, cuts(1 99) suffix(_w) label // 缩尾
sum profit_latest_w profit_latest
g log_profit_latest_w = log(profit_latest+1)

******
*投资
******

*新增投资(费用/强度/是否) 万元
g invest = b16g2  // 费用
replace invest =. if invest < 0 
g log_invest = log(invest+1)

winsor2 invest, cuts(1 99) suffix(_w) label // 缩尾
sum invest_w 
g log_invest_w = log(invest+1)

*是否投资
g invest_dummy = invest  // 是否
replace invest_dummy = 0 if invest_dummy == 0 
replace invest_dummy = 1 if invest_dummy > 0 
tab invest_dummy

*新增投资/销售收入(强度)
g invest_ratio = invest / revenue_latest
replace invest_ratio =. if invest_ratio < 0
replace invest_ratio =. if invest_ratio > 100 
g log_invest_ratio = log(invest_ratio+1)

g invest_ratio_w = invest_w / revenue_latest_w // 缩尾
replace invest_ratio_w =. if invest_ratio_w < 0
replace invest_ratio_w =. if invest_ratio_w > 100 
replace invest_ratio_w =. if invest_ratio_w > 1


************
*创新
************
*null



********************************************************************************
********************************* 资源获取 *********************************
********************************************************************************

************
*贷款
************

*银行贷款(股份制银行)(万元)
g loan_bank = b16c2a1
replace loan_bank =. if loan_bank < 0
g log_loan_bank = log(loan_bank+1)

winsor2 loan_bank, cuts(1 99) suffix(_w) label // 缩尾
sum loan_bank_w loan_bank
g log_loan_bank_w = log(loan_bank+1)

*国有银行 (万元)
*null

*城市商业银行(万元)
*null

*银行 (万元)
*null

*民间贷款 (万元)
g loan_private = b16c2c1
replace loan_private =. if loan_private < 0
g log_loan_private = log(loan_private+1)


********************************************************************************
********************************* 行政干预 *********************************
********************************************************************************

*摊派 (万元)
g tanpai = b16f4b  // 费用
replace tanpai =. if tanpai < 0 
g log_tanpai = log(tanpai+1)

*是否摊派
g tanpai_dummy = tanpai  // 是否
replace tanpai_dummy = 0 if tanpai_dummy == 0 
replace tanpai_dummy = 1 if tanpai_dummy > 0 

*摊派/销售收入
g tanpai_ratio = tanpai / revenue_latest 
replace tanpai_ratio =. if tanpai_ratio < 0
replace tanpai_ratio =. if tanpai_ratio > 100

*应酬(万元)
g yingchou = b16f4c  // 费用
replace yingchou =. if yingchou < 0 
g log_yingchou = log(yingchou+1)

*是否应酬
g yingchou_dummy = yingchou  // 是否
replace yingchou_dummy = 0 if yingchou_dummy == 0 
replace yingchou_dummy = 1 if yingchou_dummy > 0 
tab yingchou_dummy

*应酬/销售收入
g yingchou_ratio = yingchou / revenue_latest  // 强度
replace yingchou_ratio =. if yingchou_ratio < 0
replace yingchou_ratio =. if yingchou_ratio > 100

*规费(万元)
g guifei = b16e2  // 费用
replace guifei =. if guifei < 0 
g log_guifei = log(guifei+1)

*是否规费
g guifei_dummy = guifei  // 是否
replace guifei_dummy = 0 if guifei_dummy == 0 
replace guifei_dummy = 1 if guifei_dummy > 0 
tab guifei_dummy

*规费/销售收入
g guifei_ratio = guifei / revenue_latest  // 强度
replace guifei_ratio =. if guifei_ratio < 0
replace guifei_ratio =. if guifei_ratio > 100


********************************************************************************
********************************* 外部社会责任 *********************************
********************************************************************************

*******
*捐赠*
******
*drop juan log_juan juan_dummy juan_ratio

*捐赠费用
g juan = b22b/100  // 费用
replace juan =. if juan < 0 
g log_juan = log(juan+1)

winsor2 juan, cuts(1 99) suffix(_w) label // 缩尾
sum juan_w juan
g log_juan_w = log(juan_w+1)

*是否捐赠
g juan_dummy = juan  // 是否
replace juan_dummy = 0 if juan_dummy == 0 
replace juan_dummy = 1 if juan_dummy > 0 
tab juan_dummy

*捐赠费用/销售收入
g juan_ratio = juan/revenue_latest  // 强度
sum juan_ratio
replace juan_ratio =. if juan_ratio > 1

g juan_ratio_w = juan_w/revenue_latest_w  // 缩尾
sum juan_ratio_w
replace juan_ratio_w =. if juan_ratio_w > 1

**********
*治理污染*
**********
*drop zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio

*治污费用
g zhiwu = b21a  // 费用
replace zhiwu =. if zhiwu < 0 
g log_zhiwu = log(zhiwu+1)

winsor2 zhiwu, cuts(1 99) suffix(_w) label // 缩尾
sum zhiwu_w zhiwu
g log_zhiwu_w = log(zhiwu_w+1)

*是否治污
g zhiwu_dummy = zhiwu  // 是否
replace zhiwu_dummy = 0 if zhiwu_dummy == 0 
replace zhiwu_dummy = 1 if zhiwu_dummy > 0 
tab zhiwu_dummy

*治污费用/销售收入
g zhiwu_ratio = zhiwu/revenue_latest  // 强度
sum zhiwu_ratio
replace zhiwu_ratio =. if zhiwu_ratio > 1

g zhiwu_ratio_w = zhiwu_w /revenue_latest_w  // 强度
sum zhiwu_ratio_w
replace zhiwu_ratio_w =. if zhiwu_ratio_w > 1

********************************************************************************
********************************* 内部社会责任 *********************************
********************************************************************************

********
*工资*
********

*总工资
sum b20a
g wage = b20a
replace wage =. if wage < 0
g log_wage = log(wage+1)

*人均工资(手动计算)
g per_wage = wage/employee
sum per_wage
sum per_wage, de
g log_per_wage = log(per_wage+1)

winsor2 per_wage, cuts(1 99) suffix(_w) label // 缩尾
sum per_wage_w per_wage
g log_per_wage_w = log(per_wage_w+1)


********
*劳保*
********
*null

************
*社会保险*
************
sum b20d1a1 b20d2a b20d3a b20d4a b20d5a //  参保人数 (医疗/养老/工伤/失业/生育)
sum b20d1a2 b20d2b b20d3b b20d4b b20d5b // 参保费用 (医疗/养老/工伤/失业/生育)

*单项参保人数
g ins_med_num = b20d1a1
g ins_old_num = b20d2a
g ins_injury_num = b20d3a
g ins_unemploy_num = b20d4a
g ins_birth_num = b20d5a

*单项社保支出
g ins_med_fee = b20d1a2
g ins_old_fee = b20d2b
g ins_injury_fee = b20d3b
g ins_unemploy_fee = b20d4b
g ins_birth_fee = b20d5b
g log_ins_med_fee = log(ins_med_fee+1)
g log_ins_old_fee = log(ins_old_fee+1)
g log_ins_ins_injury_fee = log(ins_injury_fee+1)
g log_ins_unemploy_fee = log(ins_unemploy_fee+1)
g log_ins_ins_birth_fee = log(ins_birth_fee+1)

*人均社保费用(单项)
g per_ins_med_fee = ins_med_fee/employee
g per_ins_old_fee = ins_old_fee/employee
g per_ins_injury_fee = ins_injury_fee/employee
g per_ins_unemploy_fee = ins_unemploy_fee/employee
g per_ins_birth_fee = ins_birth_fee/employee
replace per_ins_med_fee =. if per_ins_med_fee <0
replace per_ins_old_fee =. if per_ins_old_fee <0
replace per_ins_injury_fee =. if per_ins_injury_fee <0
replace per_ins_unemploy_fee =. if per_ins_unemploy_fee <0
replace per_ins_birth_fee =. if per_ins_birth_fee <0
g log_per_ins_med_fee = log(per_ins_med_fee+1)
g log_per_ins_old_fee = log(per_ins_old_fee+1)
g log_per_ins_injury_fee = log(per_ins_injury_fee+1)
g log_per_ins_unemploy_fee = log(per_ins_unemploy_fee+1)
g log_per_ins_birth_fee = log(per_ins_birth_fee+1)

*参保率(单项)
g ins_med_num_ratio = ins_med_num / employee
g ins_old_num_ratio = ins_old_num / employee
g ins_injury_num_ratio = ins_injury_num / employee
g ins_unemploy_num_ratio = ins_unemploy_num / employee
g ins_birth_num_ratio = ins_birth_num / employee

*总社保支出
g ins_fare = b20d1a2 + b20d2b + b20d3b + b20d4b + b20d5b  // 参保费用(医疗/养老/失业)
replace ins_fare =. if ins_fare <0
g log_ins_fare = log(ins_fare+1)

*总参保人数
recode b20d1a2 b20d2b b20d3b b20d4b b20d5b (.=0)

g ins_num = b20d1a2 + b20d2b + b20d3b + b20d4b + b20d5b  // 参保人数(医疗/养老/失业)
replace ins_num =. if ins_num <0
*replace ins_num =. if b20d1a2==0&b20d2b==0&b20d3b==0&b20d4b==0&b20d5b==0



*是否有社保支出
g ins_fare_dummy = ins_fare // 是否
replace ins_fare_dummy = 0 if ins_fare_dummy == 0
replace ins_fare_dummy = 1 if ins_fare_dummy > 0

*总人均社保支出
g per_ins_fare = ins_fare/employee  
replace per_ins_fare =. if per_ins_fare <0
g log_per_ins_fare = log(per_ins_fare+1)

winsor2 per_ins_fare, cuts(1 99) suffix(_w) label // 缩尾
sum per_ins_fare_w per_ins_fare
g log_per_ins_fare_w = log(per_ins_fare_w+1)

*总参保率(参保人数/职工数)
g ins_num_ratio = ins_num / employee
replace ins_num_ratio =. if ins_num_ratio <0
replace ins_num_ratio =. if ins_num_ratio >1

********
*员工培训*
*********

*培训费用(万元)
g train_fare = b20c2  // 费用
replace train_fare =. if train_fare <0
g log_train_fare = log(train_fare+1)

*是否培训
g train_fare_dummy = train_fare // 是否
replace train_fare_dummy = 0 if train_fare_dummy == 0
replace train_fare_dummy = 1 if train_fare_dummy > 0

*人均培训(总职工数)
g per_train_fare = train_fare/employee // 人均费用
replace per_train_fare =. if per_train_fare <0
g log_per_train_fare = log(per_train_fare+1)

*培训/销售收入
g train_ratio = train_fare / revenue_latest  // 强度
replace train_ratio =. if train_ratio > 1

********
*个人合同*
*********

*个人合同签订人数
g contract_i_num = b20e1 // 人数
replace contract_i_num =. if contract_i_num <0

*个人合同签订率 = 签订人数/员工数
g contract_i_ratio = contract_i_num/employee  // 
replace contract_i_ratio =. if contract_i_ratio <0
replace contract_i_ratio =. if contract_i_ratio > 1
sum contract_i_ratio

********
*集体合同*
*********

*集体合同签订人数
g contract_c_num = b20e2 // 人数
replace contract_c_num =. if contract_c_num <0

*集体合同签订率 = 签订人数/员工数
g contract_c_ratio = contract_c_num/employee  // 签订率
replace contract_c_ratio =. if contract_c_ratio <0
replace contract_c_ratio =. if contract_c_ratio > 1


********************************************************************************
********************************* 家族涉入 *********************************
********************************************************************************

***所有者权益占比
*您自己和家人(衡量家族涉入) %
*g interest_of = b14a1b
*replace interest_of =. if interest_of <0
*replace interest_of =. if interest_of > 100
*sum interest_of

*董事长由谁担任
tab b18b 
tab b18b, nol  // 1=主要出资人本人 2=家族成员 3=外聘人才 4=其它
g boss_fam = b18b
recode boss_fam 1/2 =1 3/4=0 // 1=家族 0=非家族
tab boss_fam


********************************************************************************
*************************** Regional Level **************************
********************************************************************************

g shengfen = n1r

// 省份重新编码
g prov =.
replace	prov	=	110000	if	shengfen	==	1
replace	prov	=	120000	if	shengfen	==	2
replace	prov	=	130000	if	shengfen	==	3
replace	prov	=	140000	if	shengfen	==	4
replace	prov	=	150000	if	shengfen	==	5
replace	prov	=	210000	if	shengfen	==	6
replace	prov	=	220000	if	shengfen	==	7
replace	prov	=	230000	if	shengfen	==	8
replace	prov	=	310000	if	shengfen	==	9
replace	prov	=	320000	if	shengfen	==	10
replace	prov	=	330000	if	shengfen	==	11
replace	prov	=	340000	if	shengfen	==	12
replace	prov	=	350000	if	shengfen	==	13
replace	prov	=	360000	if	shengfen	==	14
replace	prov	=	370000	if	shengfen	==	15
replace	prov	=	410000	if	shengfen	==	16
replace	prov	=	420000	if	shengfen	==	17
replace	prov	=	430000	if	shengfen	==	18
replace	prov	=	440000	if	shengfen	==	19
replace	prov	=	450000	if	shengfen	==	20
replace	prov	=	460000	if	shengfen	==	21
replace	prov	=	500000	if	shengfen	==	22
replace	prov	=	510000	if	shengfen	==	23
replace	prov	=	520000	if	shengfen	==	24
replace	prov	=	530000	if	shengfen	==	25
replace	prov	=	540000	if	shengfen	==	26
replace	prov	=	610000	if	shengfen	==	27
replace	prov	=	620000	if	shengfen	==	28
replace	prov	=	630000	if	shengfen	==	29
replace	prov	=	640000	if	shengfen	==	30
replace	prov	=	650000	if	shengfen	==	31
tab prov

// 地区变量  2=东部 1=中部 0=西部
g diqu =.
replace	diqu	=	2	if	prov	==	110000
replace	diqu	=	2	if	prov	==	120000
replace	diqu	=	2	if	prov	==	130000
replace	diqu	=	1	if	prov	==	140000
replace	diqu	=	1	if	prov	==	150000
replace	diqu	=	2	if	prov	==	210000
replace	diqu	=	1	if	prov	==	220000
replace	diqu	=	1	if	prov	==	230000
replace	diqu	=	2	if	prov	==	310000
replace	diqu	=	2	if	prov	==	320000
replace	diqu	=	2	if	prov	==	330000
replace	diqu	=	1	if	prov	==	340000
replace	diqu	=	2	if	prov	==	350000
replace	diqu	=	1	if	prov	==	360000
replace	diqu	=	2	if	prov	==	370000
replace	diqu	=	1	if	prov	==	410000
replace	diqu	=	1	if	prov	==	420000
replace	diqu	=	1	if	prov	==	430000
replace	diqu	=	2	if	prov	==	440000
replace	diqu	=	2	if	prov	==	450000
replace	diqu	=	2	if	prov	==	460000
replace	diqu	=	0	if	prov	==	500000
replace	diqu	=	0	if	prov	==	510000
replace	diqu	=	0	if	prov	==	520000
replace	diqu	=	0	if	prov	==	530000
replace	diqu	=	0	if	prov	==	540000
replace	diqu	=	0	if	prov	==	610000
replace	diqu	=	0	if	prov	==	620000
replace	diqu	=	0	if	prov	==	630000
replace	diqu	=	0	if	prov	==	640000
replace	diqu	=	0	if	prov	==	650000
tab diqu


/***筛选变量
keep year firm_year employee log_employee  ///
	interest_total interest_of decion_big decion_big_dummy decion_manage decion_manage_dummy ///
	indus_1 indus_2 indus_3 indus_real ///
	gender edu_cate edu_dummy party_mem renda zhengxie twocm gongshanglian status_e status_s status_p status_tl ///
	structure_party ///
	revenue_latest log_revenue_latest profit_latest log_profit_latest ///
	invest log_invest invest_dummy invest_ratio log_invest_ratio  ///
	loan_bank log_loan_bank ///
	tanpai log_tanpai tanpai_dummy tanpai_ratio yingchou log_yingchou yingchou_dummy yingchou_ratio guifei log_guifei guifei_dummy guifei_ratio //
	juan log_juan juan_dummy juan_ratio zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio ///
	wage log_wage per_wage log_per_wage ///
	ins_med_num ins_old_num ins_injury_num ins_unemploy_num ins_birth_num ins_med_fee ins_old_fee ins_injury_fee ins_unemploy_fee ins_birth_fee log_ins_med_fee log_ins_old_fee log_ins_ins_injury_fee log_ins_unemploy_fee log_ins_ins_birth_fee per_ins_med_fee per_ins_old_fee per_ins_injury_fee per_ins_unemploy_fee per_ins_birth_fee log_per_ins_med_fee log_per_ins_old_fee log_per_ins_injury_fee log_per_ins_unemploy_fee log_per_ins_birth_fee ins_med_num_ratio ins_old_num_ratio ins_injury_num_ratio ins_unemploy_num_ratio ins_birth_num_ratio ins_fare log_ins_fare ins_num ins_fare_dummy per_ins_fare log_per_ins_fare ins_num_ratio ///
	train_fare log_train_fare train_fare_dummy per_train_fare log_per_train_fare train_ratio 
	contract_i_num contract_i_ratio contract_c_num contract_c_ratio ///
	boss_fam ///
	prov diqu
*/



***构建家族涉入的新指标(虚拟变量)
g interest_of_dy = .
replace interest_of_dy =0 if interest_of < 50
replace interest_of_dy =1 if interest_of > 49.9999999 & interest_of < 101
tab interest_of_dy


**********************
***数据清理***
**********************

drop if structure_party == .
*drop if ins_num_ratio==.
drop if interest_of==.
drop if log_employee == .
drop if party_ind ==.
drop if party_mem == .
drop if firm_year==.
drop if log_profit_latest== .
drop if industry_man==.
drop if firm_year==.
drop if gender == .
drop if edu_dummy == .
drop if twocm == .
drop if prov == .



***label variables
lab var structure_party "Build a Party Branch"
lab var ins_num_ratio "Percent of Employees with Social Securities"
lab var interest_of "Family Involvement"
lab var log_employee "Firm size (logged)"
lab var employee "Firm size"
lab var party_ind "Percent of Party building in an industry"
lab var firm_year "Firm age"
lab var profit_latest "Firm profit"
lab var industry_man "Manufacturing"
lab var gender "Male"
lab var edu_dummy "College education and above"
lab var twocm "Congress delegates or CCPCC members"
lab var party_mem "Party members"



**summary statistics

asdoc sum  structure_party ins_num_ratio interest_of employee  party_ind party_mem firm_year ///
profit_latest_w industry_man gender edu_dummy twocm,replace(table 2) dec(2) label



**********************
***select variables***
**********************
***Chapter 6 设立党组织

/*g year = 2012 
keep year structure_party interest_of interest_of_dy decion_big_dummy decion_manage_dummy ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_tl status_s status_p status_e ///
			diqu prov ///
			revenue_latest_w log_revenue_latest_w profit_latest_w log_profit_latest_w // 缩尾

pa_should ///
			
***Chapter 7 社会功能
*g year = 2012
keep year structure_party interest_of interest_of_dy decion_big_dummy decion_manage_dummy ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_tl status_s status_p status_e ///
			diqu prov ///
			juan log_juan juan_dummy juan_ratio zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio ///
			wage per_wage ///
			ins_fare log_ins_fare ins_num ins_fare_dummy per_ins_fare	ins_num_ratio ///
			train_fare log_train_fare train_fare_dummy	per_train_fare	train_ratio ///
			contract_i_num	contract_i_ratio contract_c_num	contract_c_ratio ///			
			revenue_latest_w log_revenue_latest_w profit_latest_w log_profit_latest_w /// 缩尾
			juan_w log_juan_w juan_ratio_w zhiwu_w log_zhiwu_w zhiwu_ratio_w /// 缩尾
			per_wage_w log_per_wage_w per_ins_fare_w log_per_ins_fare_w  // 缩尾
			
***Chapter 8 经济功能
g year = 2018
keep year structure_party interest_of interest_of_dy  ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_tl status_s status_p status_e ///
			diqu prov ///
			invest log_invest invest_dummy invest_ratio ///
			loan_bank log_loan_bank ///
			tanpai log_tanpai tanpai_dummy tanpai_ratio ///
			yingchou log_yingchou yingchou_dummy yingchou_ratio ///
			guifei log_guifei guifei_dummy guifei_ratio ///
			revenue_latest_w log_revenue_latest_w profit_latest_w log_profit_latest_w /// 缩尾
			invest_w log_invest_w invest_ratio_w /// 缩尾
			loan_bank_w log_loan_bank_w  // 缩尾

***Chapter 9 脱耦 不理想
keep year structure_party interest_of interest_of_dy decion_big_dummy decion_manage_dummy ///
	      firm_year employee log_employee revenue_latest log_revenue_latest ///
			profit_latest log_profit_latest indus_real ///
			age gender edu_dummy party_mem twocm gongshanglian status_tl status_s status_p status_e ///
			diqu prov ///
			juan log_juan juan_dummy juan_ratio zhiwu log_zhiwu zhiwu_dummy zhiwu_ratio ///
			wage per_wage ///
			ins_fare log_ins_fare ins_num ins_fare_dummy per_ins_fare	ins_num_ratio ///
			train_fare log_train_fare train_fare_dummy	per_train_fare	train_ratio ///
			contract_i_num	contract_i_ratio contract_c_num	contract_c_ratio ///
			invest log_invest invest_dummy invest_ratio ///
			loan_bank log_loan_bank ///
			tanpai log_tanpai tanpai_dummy tanpai_ratio ///
			yingchou log_yingchou yingchou_dummy yingchou_ratio ///
			guifei log_guifei guifei_dummy guifei_ratio ///
			firm_shuji party_func
*/		
			
			
********************************=********************************=**************
*************************************** 回归分析 ******************************
********************************=********************************=**************

***Table 1：家族控制对设立党组织的影响
/*g interest_of_dy = interest_of
replace interest_of_dy =0 if interest_of_dy < 50.00000001
replace interest_of_dy =1 if interest_of_dy > 50
tab interest_of_dy
*/

set more off


logit structure_party c.interest_of i.party_mem  c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m1
	
		
logit structure_party c.interest_of c.log_employee  i.party_mem c.firm_year ///
c.log_profit_latest_w i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m2

/*
logit firm_shuji c.interest_of party_ind i.party_mem c.firm_year  c.log_profit_latest ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m3

logit firm_shuji c.interest_of c.log_employee  party_ind i.party_mem c.firm_year ///
c.log_profit_latest i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m4
*/

esttab m1 m2  using decouple_2012.rtf, b(3) se(3) pr2 star(* 0.05 ** 0.01 *** 0.001) ///
nobase replace drop(*.prov*)





/**replaced dependent variables
logit structure_party interest_of_dy i.party_mem  c.firm_year c.log_profit_latest ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m11
	
		
logit structure_party interest_of_dy c.log_employee  party_ind i.party_mem c.firm_year ///
c.log_profit_latest i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m21

logit firm_shuji interest_of_dy party_ind i.party_mem c.firm_year  c.log_profit_latest ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m31

logit firm_shuji interest_of_dy c.log_employee  party_ind i.party_mem c.firm_year ///
c.log_profit_latest i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m41


esttab m11 m21 m31 m41 using decouple_2012_2.rtf, b(3) se(3) pr2 star(* 0.10 ** 0.05 *** 0.01) ///
nobase replace drop(*.prov*)

*/
***********************
***social security
***********************
regress ins_num_ratio c.interest_of i.party_mem  c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov if structure_party==1
eststo m5 


regress ins_num_ratio c.interest_of i.party_mem structure_party c.firm_year c.log_profit_latest_w ///
i.industry_man i.gender i.edu_dummy i.twocm i.prov
eststo m6


esttab m5 m6 using socrate_2012.rtf, b(3) se(3) r2 star(* 0.05 ** 0.01 *** 0.001) ///
nobase replace drop(*.prov*)


exit



probit structure_party c.interest_of c.firm_year c.log_employee c.log_profit_latest i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
    eststo
probit structure_party c.interest_of_dy c.firm_year c.log_employee c.log_profit_latest i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
    eststo
	
	
probit structure_party c.decion_big_dummy c.firm_year c.log_employee c.log_profit_latest i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
    eststo 			
esttab using chapter6_t4_2012.rtf, b(3) se(3) pr2 star(* 0.10 ** 0.05 *** 0.01) nolabel replace
eststo clear


***Table 1：家族控制对设立党组织的影响
probit structure_party c.interest_of c.firm_year c.log_employee c.log_profit_latest c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
//"结果：显著"
probit structure_party c.decion_big_dummy  c.firm_year c.log_employee c.log_profit_latest c.interest_of  i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
//"结果：显著"


***Table 1:制度环境与设立党组织***

/*地位感知*/
probit structure_party c.status_e c.firm_year c.log_employee c.log_profit_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
probit structure_party c.status_s c.firm_year c.log_employee c.log_profit_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
probit structure_party c.status_p c.firm_year c.log_employee c.log_profit_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
probit structure_party c.status_tl c.firm_year c.log_employee c.log_profit_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

//"结果:社会地位和政治地位越低，建立党组织的几率越小"


***Table 2:党组织对企业绩效的影响***

/*企业绩效*/
*销售收入 yes
reg log_revenue_latest i.structure_party c.firm_year c.log_employee c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*净利润 yes
reg log_profit_latest i.structure_party c.firm_year c.log_employee c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

/*新增投资*/
*投资额 no
reg log_invest i.structure_party c.firm_year c.log_employee c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*新增投资/销售收入 no
reg log_invest i.structure_party c.firm_year c.log_employee c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

/*资源获取*/
*银行贷款
reg log_loan_bank i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

/*行政干预*/
*摊派 no
reg log_tanpai i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*应酬 no 
reg log_yingchou i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*规费 no
reg log_guifei i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

/*内部社会责任*/
*工资 yes
reg log_wage i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
reg log_per_wage i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*劳保 null
*社保 yes
reg log_per_ins_fare i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*培训 yes
reg log_per_train_fare i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
*合同签订 yes
reg contract_i_ratio i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
reg contract_c_ratio i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov

/*外部社会责任*/
*捐赠 yes
reg log_juan i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov
reg juan_ratio i.structure_party c.firm_year c.log_employee c.log_revenue_latest c.interest_of c.decion_big_dummy i.indus_real i.gender i.edu_dummy i.party_mem i.twocm i.prov


























































